import {defineConfig} from "vite";
import vue from "@vitejs/plugin-vue";
import {viteMockServe} from "vite-plugin-mock";
// @ts-ignore
import eslintPlugin from "vite-plugin-eslint";
import stylelint from "vite-plugin-stylelint";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import {ElementPlusResolver} from "unplugin-vue-components/resolvers";

// https://vite.dev/config/
export default defineConfig(({command}) => {
    // const env = loadEnv(mode, process.cwd());
    return {
        plugins: [
            vue(),
            AutoImport({
                resolvers: [ElementPlusResolver()],
            }),
            Components({
                resolvers: [ElementPlusResolver()],
            }),
            viteMockServe({
                mockPath: "./src/mock", // mock文件存放的位置
                enable: command === "serve", // 在 mock 模式中启用 mock
            }),
            eslintPlugin({
                include: ["src/**/*.{js,ts,tsx,vue}"], //指定需要检查的文件
                exclude: ["dist/**", "src/**/*.d.ts"],                  //指定不需要检查的文件
                fix: false,                            //是否自动修复
                // cache: false                           //是否启用缓存
            }),
            stylelint({
                include: ["src/**/*.{css,scss,sass,less,vue}"],          //指定需要检查的文件
                exclude: ["dist/**", "src/**/*.d.ts"],                  //指定不需要检查的文件
                fix: false,                            //是否自动修复
                // cache: false                           //是否启用缓存
            }),
        ],
        css: {
            preprocessorOptions: {
                scss: {
                    javascriptEnabled: true,
                    // 当前版本sass已抛弃@import命令，改用@use
                    additionalData: '@use "/src/styles/variable.scss" as *;',
                },
            },
        },
        //跨域代码
        server: {
            port: 3000,
            // proxy: {
            //   [env.BASE_API]: {
            //     // 获取数据的服务器地址
            //     target: env.PROD_API,
            //     //需要跨域代理
            //     changeOrigin: true,
            //     //路径重写
            //     rewrite: (path) => path.replace(/^\api/, ""),
            //   },
            // },
        },
    };
});
